package br.com.lucasddaniel.inbuzios.activities;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import br.com.lucasddaniel.inbuzios.R;

public class MenuActivity extends Activity implements OnClickListener {

    private final String ERRO = "Erro";
    private final String ALERTA = "Alerta";
    private final Handler mHandler = new Handler();

    private ImageView imgTuristas;
    private ImageView imgPacotes;
    // private ImageView imgImportarDados;
    // private ImageView imgExportarDados;
    private ImageView imgCadastro;
    private ImageView imgConfigRelatorio;
    private boolean showMenu;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_menu);
        Intent i = getIntent();
        if (i.getExtras() != null) {
            showMenu = i.getBooleanExtra("showMenu", false);
        }
        initializeComponents();
    }

    private void initializeComponents() {
        imgPacotes = (ImageView) findViewById(R.id_activity_menu.img_pacotes);
        imgTuristas = (ImageView) findViewById(R.id_activity_menu.img_turistas);
        imgCadastro = (ImageView) findViewById(R.id_activity_menu.img_cadastro);
        imgConfigRelatorio = (ImageView) findViewById(R.id_activity_menu.img_conf_relat);

        imgPacotes.setOnClickListener(this);
        imgTuristas.setOnClickListener(this);
        imgCadastro.setOnClickListener(this);
        imgConfigRelatorio.setOnClickListener(this);
    }

    public void onClick(View view) {
        switch (view.getId()) {
            case R.id_activity_menu.img_turistas:
                startActivity(new Intent(this, ListarTuristasActivity.class));
                break;
            case R.id_activity_menu.img_pacotes:
                startActivity(new Intent(this, ListarPacotesActivity.class));
                break;
            case R.id_activity_menu.img_cadastro:
                Intent i = new Intent(this, TuristasActivity.class);
                i.putExtra("fromMenu", true);
                startActivity(i);
                break;
            case R.id_activity_menu.img_conf_relat:
                startActivity(new Intent(this, ConfiguracoesActivity.class));
                break;
        }

    }

    /**
     * Exibe uma mensagem ao usuario de acordo com os parametros passados. Usada em excessoes.
     * 
     * @param titulo
     * @param message
     */
    protected void notificarUsuario(final String titulo, final String message) {
        mHandler.post(new Runnable() {
            public void run() {
                new AlertDialog.Builder(MenuActivity.this).setTitle(titulo).setMessage(message).create().show();
            }
        });
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        if (showMenu) {
            menu.add(Menu.NONE, Menu.FIRST, Menu.NONE, getResources().getString(R.string.menu_label_custom));
        }
        return super.onCreateOptionsMenu(menu);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        if (item.getItemId() == Menu.FIRST) {
            Intent intent = new Intent(this, CadastroResponsavelActivity.class);
            this.startActivity(intent);
        }

        return super.onOptionsItemSelected(item);
    }
}
